$(function () {

    //定义搜索区域字段
    let searchValues = [
        {
            id: "textSearchKey",
            field: "key",
            title: "流程标识"
        },
        {
            id: "textSearchName",
            field: "name",
            title: "流程名称"
        },
        {
            id: "comboSearchCategory",
            field: "category",
            title: "模型类型",
            comboUrl: "/system/sysDict/listByParentValue",
            comboData: {
                value: "MODEL_TYPE"
            },
            comboId: "value",
            comboText: "name"
        }
    ];

    //初始化搜索区域
    JEE.initSearch({
        panelTitle: "查询",
        searchValues: searchValues,
        defaultTable: "tb_data" //关联表格id
    });

    //初始化表格
    JEE.initTable({
        button: [
            {
                btnId: "btn_import",
                btnCss: "btn",
                btnText: "导入",
                onClick: function () {
                    showDialog();
                }

            },
            {
                btnId: "btn_delete",
                btnCss: "btn btn-danger",
                btnText: "删除",
                onClick: function () {
                    let selections = $("#tb_data").bootstrapTable("getSelections");

                    if (selections.length != 1) {
                        JEE.error("请选择需要删除的数据！");
                        return;
                    }

                    JEE.confirmMsg("该操作为级联,是否确认删除数据？", function () {
                        $.when(JEE.ajax(oaUrl + "/activity/customProcess/deleteProcess", {deploymentId: selections[0].deploymentId})).done(function (res) {
                            if (res) {

                            }
                        });
                    });
                    layer.closeAll('dialog');
                }
            }
        ],
        tableId: "tb_data",
        mainSearch: searchValues,
        url: oaUrl + "/activity/customProcess/listByPage",
        columns: [
            {
                checkbox: true
            },
            {
                field: "key",
                title: "流程标识"
            },
            {
                field: "name",
                title: "流程名称"
            },
            {
                field: "resourceName",
                title: "XML资源",
                formatter: function (val, row, index) {
                    return '<a href="' + oaUrl + '/activity/customProcess/getResource' +
                        '?resourceType=xml&processDefinitionId=' + row.id + '"' +
                        'target="_blank">' + val + '</a>';
                }
            },
            {
                field: "diagramResourceName",
                title: "图片资源",
                formatter: function (val, row, index) {
                    return '<a href="' + oaUrl + '/activity/customProcess/getResource' +
                        '?resourceType=image&processDefinitionId=' + row.id + '"' +
                        'target="_blank">' + val + '</a>';
                }
            },
            {
                field: "version",
                title: "版本"
            },
            {
                field: "description",
                title: "流程描述"
            }
        ]
    });
});

//弹出框
function showUploadDialog(change) {
    index = JEE.initDialog({
        title: "新增",
        data: data,
        url: "ProcessForm.html",
        disable: {}
    });
}
